home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / jpeg / libCLRjpeg4 / example / jpaste.c next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  135 lines

  1. /* includes */
  2. #include <stdio.h>
  3. #include <gl.h>
  4. #include <device.h>
  5.  
  6. extern char * optarg;
  7. extern int optind;
  8.  
  9. /************************************************************************
  10. *
  11. *  usage
  12. *
  13. *  print the usage string
  14. *
  15. *************************************************************************/
  16.  
  17. void
  18. usage (char * progname)
  19. /* complain about bad command line */
  20. {
  21.    fprintf(stderr, "usage: %s ", progname);
  22.    fprintf(stderr, "[-n] [-o x,y] [-f] file\n\n");
  23.    fprintf(stderr, "-n       do not diplay a border on the window\n");
  24.    fprintf(stderr, "-o x,y   start the window's lower-left corner at this\n");
  25.    fprintf(stderr, "         screen position (relative to bottom left corner\n");
  26.    fprintf(stderr, "-f       start the program in the foreground\n");
  27.    fprintf(stderr, "file     the name of the file to display\n");
  28.    fprintf(stderr, "\n");
  29.    fprintf(stderr,"This program will open a window and display a jpeg\n");
  30.    fprintf(stderr,"image (if it is in JFIF format and does NOT use\n");
  31.    fprintf(stderr,"arithmetic coding).  The decoding process utilizes\n");
  32.    fprintf(stderr,"the Independent JPEG Group's software (%s).\n",GetJPEGVersion());
  33.    fprintf(stderr,"IRIS GL(tm) Adaption is\n");
  34.    fprintf(stderr,"(c) 1992 Rodney Hoinkes, Centre for Landscape Research\n");
  35.    fprintf(stderr,"This software is public domain.\n");
  36.    exit(2);
  37. }
  38.  
  39. char WindowName[256];
  40. char NoBorder = 0, NoFork = 0, PrefOrg = FALSE;
  41. int window_x, window_y;
  42.  
  43. main(argc,argv)
  44. int argc;
  45. char *argv[];
  46. {
  47.    int c;
  48.     long *imageptr;
  49.     int xsize, ysize;
  50.  
  51.    while ((c = getopt(argc, argv, "nfo:")) != -1) {
  52.       switch (c) {
  53.        case 'n':
  54.      NoBorder = 1;
  55.      break;
  56.        case 'f':
  57.      NoFork = 1;
  58.      break;
  59.        case 'o':
  60.      if (optarg == NULL)
  61.         usage(argv[0]);
  62.      if (sscanf(optarg, "%d,%d", &window_x, &window_y) != 2)
  63.         usage(argv[0]);
  64.      PrefOrg = TRUE;
  65.      break;
  66.        case '?':
  67.        default:
  68.      usage(argv[0]);
  69.      break;
  70.       }
  71.    }
  72.  
  73.    if (optind != argc-1) usage(argv[0]);
  74.  
  75. /* Select the input files */
  76.    
  77.    if (optind < argc-1) {
  78.       fprintf(stderr, "%s: only one input file allowed\n", argv[0]);
  79.       usage(argv[0]);
  80.    }
  81.  
  82.    strcpy(WindowName,argv[optind]);
  83.     imageptr = (long *)LoadJPEGImagePtr(WindowName,&xsize,&ysize);
  84.     SetupGraphics(xsize,ysize);
  85.     lrectwrite(0,0,xsize-1,ysize-1,imageptr);
  86.     ManageWindow(imageptr,xsize,ysize);
  87.  
  88. }
  89.  
  90. SetupGraphics(int xsize,int ysize) {
  91. /* Eric Willaims, williams@sgi.com 
  92.    -- add command line options to GL interface */
  93.  
  94.    /* open the window */
  95.    if (PrefOrg) {
  96.       prefposition(window_x, window_x + xsize - 1,
  97.            window_y, window_y + ysize - 1);
  98.       if (NoBorder) noborder();
  99.       if (NoFork) foreground();
  100.       winopen(WindowName);
  101.       prefsize(xsize,ysize);
  102.       if (NoBorder) noborder();
  103.       winconstraints();
  104.    } else {
  105.       prefsize(xsize,ysize);
  106.       if (NoBorder) noborder();
  107.       if (NoFork) foreground();
  108.       winopen(WindowName);
  109.    }
  110.    
  111.    /* set the display mode for the image */
  112.    RGBmode();
  113.    singlebuffer();
  114.    gconfig();
  115.    cpack(0xffffffff);
  116.    clear();
  117. }
  118.  
  119. ManageWindow(long *imageptr,int xsize,int ysize) {
  120.     long val;
  121.     short type;
  122.  
  123.     while(1) {
  124.         if(qtest()) {
  125.             val = qread(&type);
  126.             switch(val) {
  127.                 case REDRAW:
  128.                 case INPUTCHANGE:
  129.                     lrectwrite(0,0,xsize-1,ysize-1,imageptr);
  130.                     break;
  131.             }
  132.         }
  133.     }
  134. }
  135.